package com.adlotto2.android.cronos.parser;

import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import com.adlotto2.android.cronos.data.CNLottoListData;
import com.adlotto2.android.cronos.datahandler.CNBaseDataParser;
import com.adlotto2.android.cronos.datahandler.CNResultSet;

public class CNLottoListParser extends CNBaseDataParser{
	protected void onParseContent(Element xmlObject, CNResultSet resultSet)
			throws Exception {
		
		NodeList nodeList = xmlObject.getElementsByTagName("lottoRec");
		
		NodeList nodeSendSeq = xmlObject.getElementsByTagName("sendSeq");
		NodeList nodeThumb = xmlObject.getElementsByTagName("attachFileThumb");
				
		NodeList totalCntNode = xmlObject.getElementsByTagName("totalCount");
		String totalCnt = totalCntNode.item(0).getFirstChild().getNodeValue();
		resultSet.setTotalCount(Integer.parseInt(totalCnt));
		
		int count = nodeList.getLength();
		
		for (int i = 0; i < count; i++)
		{
			Element elementData = (Element) nodeList.item(i);
			if (elementData == null)
				continue;
			
			CNLottoListData dataSet = new CNLottoListData();
			
			if(nodeSendSeq.item(i).getFirstChild() != null)
				dataSet.sendSeq = Integer.parseInt(nodeSendSeq.item(i).getFirstChild().getNodeValue());
			
			if(nodeThumb.item(i).getFirstChild() != null)
				dataSet.adThumb = nodeThumb.item(i).getFirstChild().getNodeValue();
			
			resultSet.addDataSet(dataSet);
		}
	}
}
